#include<iostream>
using std::endl;
using std::cout;

//基类与派生类之间的转换
//基 ————》派生类是可以的
//掌握一个整体的思想
class Point{
public:
    Point(int x,int y)
    :_x(x)
    ,_y(y){}
    void Print(){
        cout<<"Point : point"<<endl;
    }
    virtual void test(){}
protected:
    int _x;
    int _y;
};

class Point3D
:public Point{
public:
    Point3D(int x,int y,int z)
    :Point(x,y)
    ,_z(z){}
    void Print(){
        cout<<"Point3D : point3D"<<endl;
    }
protected:
    int _z;
};

int main(void){
    //其实合法
    Point *p1 = new Point3D(2,4,5);
    Point3D *p2 = dynamic_cast<Point3D*>(p1);//使用dynamic_cast 需要多态
    if(p1 != nullptr){
        cout<<"转换成功"<<endl;
        p2->Print();
    }
    else{
        cout<<"转换失败"<<endl;
    }
    
}